package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/admin/order")
@RestController("OrderAdminController")
@Api("订单管理相关接口")
@Slf4j
public class OrderController {

    @Autowired
    private OrderService orderService;
    private Object ordersRejectionDTO;

    @ApiOperation("订单搜索")
    @GetMapping("/conditionSearch")
    public Result getPage(OrdersPageQueryDTO ordersPageQueryDTO)
    {
        PageResult page = orderService.getOrderPageAdmin(ordersPageQueryDTO);
        return Result.success(page);
    }

    //各个状态的订单数量统计
    @ApiOperation("各个状态的订单数量统计")
    @GetMapping("/statistics")
    public Result NumberEverOrder()
    {
        OrderStatisticsVO orderStatisticsVO =orderService.getOrderStatusEver();
        return Result.success(orderStatisticsVO);
    }


    //查询订单详情
    @GetMapping("/details/{id}")
    @ApiOperation("查询订单详情")
    public Result<OrderVO> getOrderDetail(@PathVariable Long id)
    {
        OrderVO orderVO = orderService.getOrderDetailByOrderIdAdmin(id);
        return Result.success(orderVO);
    }

    //接单
    @PutMapping("/confirm")
    @ApiOperation("接单")
    public Result receptOrder(@RequestBody OrdersConfirmDTO ordersConfirmDTO)
    {
        ordersConfirmDTO.setStatus(Orders.CONFIRMED);
        orderService.receptOrderById(ordersConfirmDTO);
        return Result.success();
    }

    @PutMapping("/rejection")
    @ApiOperation("拒单")
    public Result RejectOrder(@RequestBody OrdersRejectionDTO ordersRejectionDTO)
    {
        orderService.rejectOrder(ordersRejectionDTO);
        return Result.success();
    }

    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public Result RejectOrder(@RequestBody OrdersCancelDTO ordersCancelDTO)
    {
        orderService.cancelOrderByIdAdmin(ordersCancelDTO);
        return Result.success();
    }

    @PutMapping("/delivery/{id}")
    @ApiOperation("派送订单")
    public Result deliverOrder(@PathVariable Long id)
    {
        orderService.deliverOrderById(id);
        return Result.success();
    }

    @PutMapping("/complete/{id}")
    @ApiOperation("完成订单")
    public Result completeOrder(@PathVariable Long id)
    {
        orderService.completeOrderById(id);
        return Result.success();
    }
}
